package org.paradise.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.paradise.dao.*;
import org.paradise.pojo.*;
import org.paradise.pojo.Package;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/Taocan")
public class TaocanController {
    @Autowired
    private PackageDao packageDao;
    @Autowired
    private PacktypeDao packtypeDao;
    @Autowired
    private ShoppingTypeDao shoppingTypeDao;
    @Autowired
    private ShoppingDao shoppingDao;
    @Autowired
    private VipTypeDao vipTypeDao;
    @RequestMapping("/list")
    @ResponseBody
    public  Map<String,Object> list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit,Package packages)throws Exception{
        Map<String,Object> map=new HashMap<>();
        Page<Vip> pager= PageHelper.startPage(page,limit);
        List<Package> list=packageDao.getList(packages);
        map.put("code",0);
        map.put("msg",null);
        map.put("data",list);
        map.put("count",pager.getTotal());
        return map;
    }
    @RequestMapping("/caotanall")
    @ResponseBody
    public List<PackageType> caotanall() throws Exception{
        return packtypeDao.getAll();
    }
    @RequestMapping("/addtaocan")
    @ResponseBody
    public Map<String,Object> addtaocan(PackageType packageType) throws Exception{
        Map<String,Object> map=new HashMap<>();
        packtypeDao.add(packageType);
        return map;
    }
    @RequestMapping("/shoppingtype")
    @ResponseBody
    public List<ShoppingType> shoppingtype() throws Exception{
        return shoppingTypeDao.getAll();
    }
    @RequestMapping("/shoppingid")
    @ResponseBody
    public Map<String,Object> shoppingall(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        List<Shopping> list=shoppingDao.getshoppingid(id);
        map.put("code",0);
        map.put("msg",null);
        map.put("data",list);
        return map;
    }
    @RequestMapping("/shoppingtypeid")
    @ResponseBody
    public ShoppingType shoppingtypeid(Integer id) throws Exception{
        return  shoppingTypeDao.get(id);
    }
    @RequestMapping("/taocanadd")
    @ResponseBody
    public Map<String,Object> taocanadd(Package packages) throws Exception{
        Map<String,Object> map=new HashMap<>();
       packageDao.add(packages);
        return map;
    }
    @RequestMapping("/deltaocan")
    @ResponseBody
    public Map<String,Object> deltaocan(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        packageDao.delete(id);
        return map;
    }
    @RequestMapping("/updatetaocan")
    @ResponseBody
    public Map<String,Object> updatetaocan(Package packages) throws Exception{
        Map<String,Object> map=new HashMap<>();
        packageDao.update(packages);
        return map;
    }
    @RequestMapping("/cardid")
    @ResponseBody
    public List<VipType> cardid() throws Exception{
        return vipTypeDao.getAll();
    }

    @RequestMapping("/getPackage")
    @ResponseBody
    public Package getPackage(Integer id) throws Exception{
        return  packageDao.getpackageid(id);
    }
}
